<?php
// +----------------------------
// | Created by PhpStorm
// +----------------------------
// | Author: YnnSon
// +----------------------------
namespace app\api\model;

class China extends BaseModel
{
    /**
     * @Desc 获取省市列表
     * @return array
     */
    public static function getList()
    {
        $province_list = (new self)->field('id, name')->where('pid', '=', 0)->where('id', '<>', 0)->select()->toArray();
        $pids = array_column($province_list, 'id');
        $province_list = array_column($province_list, 'name', 'id');
        $city_list = (new self)->field('id, name')->whereIn('pid', $pids)->select()->toArray();
        $city_list = array_column($city_list, 'name', 'id');
        return [
            'province_list' => $province_list,
            'city_list'     => $city_list,
        ];
    }
}